package com.ctshk.rpc.order.hotel.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.IsDeletedCode;
import com.ctshk.common.enums.SystemError;
import com.ctshk.rpc.hotel.service.IHotelOrderRefundService;
import com.ctshk.rpc.order.hotel.entity.HotelOrderRefund;
import com.ctshk.rpc.order.hotel.mapper.HotelOrderRefundMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;
import java.util.Objects;

/**
 * <p>
 * 酒单退款记录 服务实现类
 * </p>
 *
 * @author yinhuan
 * @since 2021-03-08
 */
@DubboService
public class HotelOrderRefundServiceImpl extends ServiceImpl<HotelOrderRefundMapper, HotelOrderRefund> implements IHotelOrderRefundService {
    @Autowired
    private HotelOrderRefundMapper hotelOrderRefundMapper;

    @Override
    public Result refund(Long refundId, Long userId) {
        HotelOrderRefund hotelOrderRefund = hotelOrderRefundMapper.selectById(refundId);
        if(Objects.isNull(hotelOrderRefund)){
            return Result.failed(SystemError.HOTEL_10033);
        }
        hotelOrderRefund.setStatus(1);
        hotelOrderRefund.setGmtModified(LocalDateTime.now());
        hotelOrderRefund.setModifiedId(userId);
        hotelOrderRefundMapper.updateById(hotelOrderRefund);
        return Result.success();
    }

    @Override
    public Result delete(Long refundId, Long userId) {
        HotelOrderRefund hotelOrderRefund = hotelOrderRefundMapper.selectById(refundId);
        if(Objects.isNull(hotelOrderRefund)){
            return Result.failed(SystemError.HOTEL_10033);
        }
        hotelOrderRefund.setIsDeleted(IsDeletedCode.NO.getCode());
        hotelOrderRefund.setGmtModified(LocalDateTime.now());
        hotelOrderRefund.setModifiedId(userId);
        hotelOrderRefundMapper.updateById(hotelOrderRefund);
        return Result.success();
    }
}
